package api.actions;

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFileChooser;
import javax.swing.JScrollPane;
import javax.swing.filechooser.FileNameExtensionFilter;

import api.components.ButtonTabComponent;
import api.components.ImagePanel;
import api.image.*;

import api.Interface;

public class Open {
	public static void run() {
		
		int value = Interface.FileChooser.showOpenDialog(Interface.frame);
		
		if (value == JFileChooser.APPROVE_OPTION) {
			File fin = Interface.FileChooser.getSelectedFile();
			
			try {
				BufferedImage img = ImageIO.read(fin);
				MyImage image = new MyImage(fin, img, true);
				
				JScrollPane scrollPane = new JScrollPane();
				
				ImagePanel ip = new ImagePanel(image);				
				scrollPane.setViewportView(ip);
				scrollPane.setBackground(new Color(0,0,0,0));
				
				Interface.panelImagen.addTab(fin.getName(), scrollPane);
				Interface.panelImagen.setTabComponentAt(Interface.panelImagen.getTabCount() - 1,
						new ButtonTabComponent(Interface.panelImagen));
				
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		
			Interface.mFClose.setEnabled(true);
			Interface.btnCancel.setEnabled(true);
		}	
	}
}
